<?php
    //1.引入文件，连接数据库
   require_once ('common/conn.php');

    // 3. 查新文章列表
    if(isset($_GET['submit'])){     //按关键字查询
        $keyword = $_GET['keyword'];
        $sql2 = "select * from article where title like '%$keyword%'";
    } else if (isset($_GET['name'])) { // 按分类查询
        if($_GET['name'] == '按点击率'){
            $sql2 = "select * from  article order by click desc";
        } else if ($_GET['name'] == '全部文章') {
            $sql2 = "select * from  article";
        } else {
            $sql2 = "select *  from article where category = '{$_GET['name']}'";
        }
    } else {// 查询所有
        $sql2 = "select *  from article";
    }
    $result2 = mysqli_query($link, $sql2);
    if($result2 === false){
        mysqli_close($link);
        exit('查询失败');
    }
    $rows2 = mysqli_fetch_all($result2,MYSQLI_ASSOC);

?>
<!DOCTYPE html>
<html>

    <head>
        <title>Roem Blog</title>
        <meta charset="utf-8">
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link href="css/bootstrap.css" rel="stylesheet">
        <link href="css/index.css" rel="stylesheet">
    </head>

    <body>

        <!-- header -->
        <div class="main-header">
            <div id="blogTitle">
                <h2>Roem的博客</h2>
                <h5>Love Coding, Roem Life !</h5>
            </div>
            <div class="nav row">
                <div class="col-md-6 col-md-offset-3">
                    <div class="row">
                        <div class="col-md-4"><a class="animation" href="index.php">文章 Articles</a></div>
                        <div class="col-md-4"><a class="animation" href="contact.php">留言 Contact</a></div>
                        <div class="col-md-4"><a class="animation" href="about.html">简介 About</a></div>
                    </div>
                </div>
            </div>
        </div>

        <!-- main -->
        <div class="content-warp" id="barba-wrapper" aria-live="polite">

            <!-- left -->
            <div class="container barba-container" style="visibility: visible;">
                <div class="row">

                    <!--start main content aera-->
                    <div class="col-md-9  main-content">

                        <div class="posts nav-info  animation">
                            <p class="posts-info">最新文章</p>
                        </div>

                        <?php foreach($rows2 as $value):?>
                        <div class="posts animation">
                            <h4 class="posts-title">
                                <a href="article.php?id=<?=$value['id']?>" class="animation"><?=$value['title']?></a>
                            </h4>
                            <p class="time">
                                作者 <?=$value['author']?>
                                &nbsp;
                                <?=date('Y-m-d H:i:s', $value['add_time']);?>
                                点击率：<?=$value['click']?>
                            </p>
                            <img style="max-height: 300px;" src="<?=$value['img']=='' ? 'img/yhzs.jpg' : 'admin/'. $value['img'] ?>" alt="">
                            <p class="descript">
                                <?=$value['content']?>
                            </p>

                            <div class="posts-footer">
                                分类:
                                <a class="class animation" href="/blog/posts/0"><?=$value['category']?></a>
                            </div>
                        </div>
                        <?php endforeach; ?>

                        <div class="page-nav animation clearfix"></div>
                    </div>


                    <!-- right -->
                    <?php require_once "right.php"; ?>

                </div>
            </div>
        </div>


        <!-- footer -->
        <div class="main-footer">
            <div class="container">
                <div class="logo">
                    ROEM BLOG
                </div>
            </div>

            <h5 class="copyright text-center">
                © 2017 &nbsp;|&nbsp; &copy; by Roem
                <a href="admin/login.php" class="no-barba no-barba-prefetch">后台管理</a>
            </h5>
        </div>
    </body>

</html>